<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div v-if="students.length==0">这个班级还没有学生</div>
        <div v-else>
            <ul>
                <!-- background-color这种有-的在js中容易有问题，所以需要引号包裹，或者写成backgroundColor驼峰命名的样子，然后Vue会帮我们转换 -->
                <!-- @click="selectedStudent=name：当li被单击的时候，把name赋值给selectedStudent -->
                <li v-for="name in students" :key="name"
                    :style="{'background-color':selectedStudent==name?'yellow':'transparent'}"
                    @click="selectedStudent=name">
                    {{ name }}
                </li>
            </ul>
        </div>
    </div>
    <script src="../assets/vue2.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data() {
                return {
                    student: '', // v-model的变量
                    selectedStudent: '',// 初始化
                    students: ['张三', '李四', '王二', '赵五', '老六']
                }
            },
        })
    </script>
</body>

</html>